package com.hclc.entity.model.validate;


import org.springframework.util.CollectionUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

public class NotEmptyListValidator implements ConstraintValidator<NotEmptyList, Object> {

    @Override
    public void initialize(NotEmptyList constraintAnnotation) {
    }


    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        //null时不进行校验
        if (CollectionUtils.isEmpty((List)value)) {
            //获取默认提示信息
            //String defaultListConstraintMessage = context.getDefaultConstraintMessageTemplate();
            //禁用默认提示信息
            //context.disableDefaultConstraintViolation();
            //设置提示语
            //context.buildConstraintViolationWithTemplate("集合不能为空!").addConstraintViolation();
            return false;
        }
        return true;
    }
}
